package ssm.myspring;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

public class App {
    public static void main(String[] args) {
        //实例化BeanFactory
        Resource res = new ClassPathResource("/spring/spring-mvc.xml");
        BeanFactory bf = new XmlBeanFactory(res);

        //注册InstantiationAwareBeanPostProcessor后置处理器，
        //因为InstantiationAwareBeanPostProcessor继承了BeanPostProcessor，
        //所以不再单独注册BeanPostProcessor后置处理器
        ((ConfigurableBeanFactory)bf).addBeanPostProcessor(new MyInstantiationAwareBeanPostProcessor());

        //获得bean
        MyBean bean = bf.getBean("myBean", MyBean.class);
        bean.printName();

        //销毁所有Bean
        ((XmlBeanFactory)bf).destroySingletons();
    }
}